package kiwi.assist.dev.guieditor.command {
	import kiwi.assist.dev.guieditor.event.GUIOperateEvent;
	import kiwi.assist.dev.guieditor.model.UiDetailVO;
	import kiwi.assist.dev.util.SkinComponentAdapter;
	import kiwi.util.asserts.assert;

	import org.robotlegs.mvcs.Command;

	import flash.display.DisplayObject;

	/**
	 * 移除UI
	 * @author jianxiang.zi
	 */
	public class RemoveUiCommand extends Command {
		[Inject]
		public var event : GUIOperateEvent;
		[Inject]
		public var detail : UiDetailVO;
		private var ui : DisplayObject;

		override public function execute() : void {
			super.execute();
			ui = event.targetUi;
			var index : int;
			if (ui is SkinComponentAdapter) {
				index = detail.backgroundSkinList.indexOf(ui);
				assert(index >= 0, "不存在的背景");
				detail.backgroundSkinList.splice(index, 1);
			} else {
				index = detail.uiList.indexOf(ui);
				assert(index >= 0, "不存在的实例");
				detail.uiList.splice(index, 1);
				delete detail.configList[ui];
			}
			if (detail.currentEditUi == ui) {
				detail.currentEditUi = null;
			}
		}
	}
}
